/**
 * @(#) DailyMediator.as
 *
 * @date		2009. 04. 03.
 * @version		1.0
 * @author		Shin, Yunwoo
 * @description	상시출장  신청 - Mediator
 * 				상시출장을 조회하고 신청하는 Presentation Logic을 관리
 */
package com.skt.common_hr.biztrip_sac.view
{
	import com.skt.common_hr.biztrip_sac.BizTripFacade;
	import com.skt.common_hr.biztrip_sac.model.BizTripBudgetProxy;
	import com.skt.common_hr.biztrip_sac.model.DailyApprovalProxy;
	import com.skt.common_hr.biztrip_sac.model.DailyBizTripProxy;
	import com.skt.common_hr.biztrip_sac.model.DailyCostProxy;
	import com.skt.common_hr.biztrip_sac.model.vo.AdjustmentVO;
	import com.skt.common_hr.biztrip_sac.model.vo.BizTripListVO;
	import com.skt.common_hr.biztrip_sac.model.vo.BizTripPlaceVO;
	import com.skt.common_hr.biztrip_sac.model.vo.BizTripSummaryVO;
	import com.skt.common_hr.biztrip_sac.model.vo.DailyCostVO;
	import com.skt.common_hr.biztrip_sac.view.components.DailyBizTrip;
	import com.skt.common_hr.common.Variables;
	import com.skt.common_hr.common.approval.RequestApprovalMediator;
	import com.skt.common_hr.common.components.CommonAlert;
	import com.skt.common_hr.common.components.alert2;
	import com.skt.common_hr.common.puremvc.CommonMediator;
	import com.wcl.components.Hourglass;
	import com.wcl.utils.DateUtil;
	import com.wcl.utils.StringUtil;
	
	import flash.events.Event;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	import mx.core.IFlexDisplayObject;
	import mx.managers.PopUpManager;
	import mx.resources.ResourceManager;
	
	import org.puremvc.as3.multicore.interfaces.INotification;

	public class DailyMediator extends CommonMediator
	{
		public static const NAME:String = "DailyMediator";

		private var key1:String;
		private var key2:String;
		private var TRSTATUS:String = "21";
		private var bModify:Boolean = true;

		private var bWaitingApproval:Boolean = false;
		private var _currentKey:String = "";
		private var currentDate:Date = new Date;
		/**
		* 생성자
		*
		* @param
		* @return void
		*/
        public function DailyMediator( viewComponent:Object )
        {
            super( NAME, viewComponent );
            view.callLater(initView);
        }

		/**
		* View를 초기화 한다.
		*	- View에 기본사항을 출력하고 data를 load
		* @param
		* @return void
		*/
 		private function initView():void
 		{
 			initDataProvider();
			//loadBizTripList();
			//set event handlers...
			view.addEventListener(DailyBizTrip.CHANGED_TERM, onChangedTerm);
			
			view.addEventListener(DailyBizTrip.ADD_RECORD, onAddRecord);
			view.addEventListener(DailyBizTrip.DEL_RECORD, onDelRecord);
			view.addEventListener(DailyBizTrip.SAVE, onSave);
			view.addEventListener(DailyBizTrip.APPROVAL, onApproval);
			view.addEventListener(DailyBizTrip.CANCEL, onInputCancel);
 		}
 		
 		private function removeEventListeners():void
 		{
 			view.removeEventListener(DailyBizTrip.CHANGED_TERM, onChangedTerm);
			
			view.removeEventListener(DailyBizTrip.ADD_RECORD, onAddRecord);
			view.removeEventListener(DailyBizTrip.DEL_RECORD, onDelRecord);
			view.removeEventListener(DailyBizTrip.SAVE, onSave);
			view.removeEventListener(DailyBizTrip.APPROVAL, onApproval);
			view.removeEventListener(DailyBizTrip.CANCEL, onInputCancel);
 		}

 		override protected function clearView():void
 		{
 			modeModify();
 			key1 = "";
 			key2 = "";
 			TRSTATUS = "21";
 			view.dailyCost = 0;
 			view.strStatus = "(신규 신청중)";
 			initDataProvider();
 		}

		private function onChangedTerm(event:Event):void
		{
			// 출장일정에 변경이 생겼으면 일비 재조정
			alignPlaceDate();
			adjustDailyCost();
		}

		private function adjustDailyCost():void
		{
			var dailyMembers:Array = new Array();
			// 일비재조정-정산중일 때만
			//if(view.bEditableAdjust) {
				loadDailyCostNew();
			//}
		}	

		private function loadDailyCostNew():void
		{
			var proxy:DailyCostProxy = facade.retrieveProxy(DailyCostProxy.NAME) as DailyCostProxy;
			//setDailyCost()
			proxy.loadDayPay(BizTripFacade.TYPE_DAILY_BIZTRIP, view.summary.BEGDA, view.placeList);
		}
					
		/**
		* 신규 생성일 경우
		*	- View를 위한 기본 테이블들을 초기화 한다.
		* @param
		* @return void
		*/
		private function initViewData():void
		{
 			key1 = "";
 			key2 = "";
 			trace("initViewData");
			// 출장 master테이블 기본 데이터 설정
			var summary:BizTripSummaryVO = new BizTripSummaryVO;
			summary.GWAREKEY01 = "";
			summary.GWAREKEY02 = "";
			summary.TRSTATUS = "11";
			summary.TRSTATX = ResourceManager.getInstance().getString(commonFacade.bundle, "STATUS_PLANNING", null, Variables.current_locale);
			summary.BEGDA = DateUtil.todayNoTime();
			summary.ENDDA = DateUtil.todayNoTime();
			summary.TRTYPE = "01";
			summary.TTEXT = ResourceManager.getInstance().getString(commonFacade.bundle, "DOMESTIC_BIZTRIP", null, Variables.current_locale);
			summary.IPERNR  = Variables.myPernr;
			summary.PURPOSE = "";
			summary.MNUM = 1;
			view.summary = summary;
			// 출장지  테이블 기본설정
			var placeList:ArrayCollection = new ArrayCollection();
			var place:BizTripPlaceVO = new BizTripPlaceVO;
			place.BEGDA = DateUtil.todayNoTime();
			place.ENDDA = DateUtil.todayNoTime();
			place.BREN = "";
			placeList.addItem(place);
			view.placeList = placeList;
		}

 		private function modeReadOnly():void
 		{
 			bModify = false;
 			view.currentState = "readonly";
 			view.bEditableBasic = false;
 		}

 		private function modeModify():void
 		{
 			bModify = true;
 			view.currentState = "";
 			view.bEditableBasic = true;
 		}
		private function initDataProvider():void
		{
			var arr:ArrayCollection = new ArrayCollection();
			currentDate = DateUtil.todayNoTime();
			arr.addItem(blankRecord());
			view.dailyDP = arr;
			loadDailyCost(1);
		}

		private function loadDailyCost(days:int):void
		{
			var proxy:DailyCostProxy = facade.retrieveProxy(DailyCostProxy.NAME) as DailyCostProxy;
			proxy.load(Variables.myPernr, BizTripFacade.TYPE_DAILY_BIZTRIP, days, new Date(), new Date());
		}


		private function loadDailyBizTrip(vo:BizTripListVO):void
		{
			key1 = vo.GWAREKEY01;
			key2 = vo.GWAREKEY02;
			TRSTATUS = vo.TRSTATUS;
			var proxy:DailyBizTripProxy = facade.retrieveProxy(DailyBizTripProxy.NAME) as DailyBizTripProxy;
			proxy.load(key1, key2);
		}

//shgoo : 2009.06.01
		/**
		*  가용예산을 로드한다.
		* @param
		* @return void
		*/
		private function loadBudget(pernr:String):void
		{
			var budgetProxy:BizTripBudgetProxy = facade.retrieveProxy(BizTripBudgetProxy.NAME) as BizTripBudgetProxy;
			budgetProxy.load(pernr, BizTripFacade.TYPE_DAILY_BIZTRIP);
		}
//////////////////////

		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Process MVC Messages
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		* 본 Class에서 처리해야할 Noti들을 등록한다.
		*
		* @param
		* @return void
		*/
		override public function listNotificationInterests():Array
		{
			return [
					BizTripFacade.LOAD_DAILY_COST_COMPLETE,
					BizTripFacade.LOAD_DAILY_COST_FAILED,
					BizTripFacade.LOAD_DAILY_BIZTRIP_COMPLETE,
					BizTripFacade.LOAD_DAILY_BIZTRIP_FAILED,
					BizTripFacade.SAVE_DAILY_BIZTRIP_COMPLETE,
					BizTripFacade.SAVE_DAILY_BIZTRIP_FAILED,
					BizTripFacade.MODIFY_DAILY_VIEW,
//shgoo : 2009.06.01
					BizTripFacade.LOAD_BUDGET_COMPLETE,
					BizTripFacade.LOAD_BUDGET_FAILED,
					BizTripFacade.LOAD_BUDGET_DAILY_REQUEST,
////////////////////
					BizTripFacade.READONLY_DAILY_VIEW,
					RequestApprovalMediator.APPROVAL_CANCEL,
					RequestApprovalMediator.APPROVAL_COMPLETE, 
					
					//0609
					DailyCostProxy.LOAD_DAILY_COST_MULTI_COMPLETE,
					DailyCostProxy.LOAD_DAILY_COST_MULTI_FAILED					
					];
		}


		/**
		* Noti별로 처리한다.
		*
		* @param
		* @return void
		*/
		public var alertView:IFlexDisplayObject = null;
		public var sType:String;
		override public function handleNotification(note:INotification):void
		{
			switch(note.getName())
			{
				case BizTripFacade.READONLY_DAILY_VIEW: 
					clearView();
					initViewData(); //silver
					loadDailyBizTrip(note.getBody() as BizTripListVO);
					modeReadOnly();
					break;
				case BizTripFacade.MODIFY_DAILY_VIEW:
					clearView();
					initViewData(); //silver
					if(note.getBody()!=null) { 
						loadDailyBizTrip(note.getBody() as BizTripListVO);
						sType = 'M';
					}else {
						sType = 'S';
					}
					modeModify();
					break;
				case BizTripFacade.LOAD_DAILY_COST_COMPLETE:
					//setDailyCost((note.getBody() as DailyCostProxy).costList.getItemAt(0) as DailyCostVO);
					
					if(view.currentState == "readonly"){
						view.cbStartHour.enabled = false;
						view.cbEndHour.enabled = false;
					}else {
						if(sType=='M'){
							view.cbStartHour.enabled = true;
							view.cbEndHour.enabled = true;
						}else {
							view.cbStartHour.enabled = false;
							view.cbEndHour.enabled = false;							
						}
					}
					break;
				case BizTripFacade.LOAD_DAILY_BIZTRIP_COMPLETE:
					setDataToView(note.getBody() as DailyBizTripProxy);
					commonFacade.setStatusMessage("STATUS_LOAD_DAILY_BIZTRIP");
					break;
				case BizTripFacade.SAVE_DAILY_BIZTRIP_COMPLETE:
					if(bWaitingApproval) {
						bWaitingApproval = false;
						_currentKey = DailyBizTripProxy(note.getBody()).outKey;
						
						//0609
						key1 = key2 = DailyBizTripProxy(note.getBody()).outKey;
						
						//CommonAlert.showMsgYesNo(commonFacade.bundle, "ALERT_ASK_APPROVAL", null, "ALERT_TITLE_INFO", null,
							//execApproval, null );
							
						alertView = PopUpManager.createPopUp(view, alert2, true);
						alert2(alertView).txtContent.htmlText 	= '저장되었습니다. 결재요청 하시겠습니까?' + 
									'<br><br>' + 
									'<P ALIGN="left"><font SIZE="12" COLOR="#0000DB">   ※ 결재요청 시 폼전송을 통한 품의서 첨부가 없어졌습니다.<br>'+
									'   ※ 증빙으로 사용할 영수증(승차권,톨비,숙박비 영수증등)이 <br>       있을 시 스캔하여 첨부하여 주시기 바랍니다.<br>' + 
									'   ※ 증빙이 없을 시에는 바로 결재요청하시면 됩니다.' + 
									'</font></p>';												
						//alert2(alertView).txtContent.htmlText 	= '저장되었습니다. 결재요청 하시겠습니까?';
								
						alert2(alertView).lbTitle.text 	= '확인';
						alert2(alertView).height 		= 190;							
						alert2(alertView).width 		= 400;
						PopUpManager.centerPopUp(alertView);
						alert2(alertView).y 		= alert2(alertView).y -50;
						
						alert2(alertView).addEventListener("yesAlert", onYes);						
						alert2(alertView).addEventListener("noAlert", onNo);							
					}
					else {
						changeListView();
					}
					break;
				case BizTripFacade.SAVE_DAILY_BIZTRIP_FAILED:
					Hourglass.remove();
					CommonAlert.showMessage(commonFacade.bundle, "("+note.getBody().retCode+")"+note.getBody().retText);
					//	_currentKey = DailyBizTripProxy(note.getBody()).outKey;
					//	CommonAlert.showMsgYesNo(commonFacade.bundle, "ALERT_ASK_APPROVAL", null, "ALERT_TITLE_INFO", null,
					//		execApproval, null );
					break;
//shgoo : 2009.06.01 가용예산 표시
				case BizTripFacade.LOAD_BUDGET_DAILY_REQUEST:
					commonFacade.setStatusMessage("STATUS_START_DAILY_BIZTRIP");
					//loadBudget(Variables.myPernr);
					break;
				case BizTripFacade.LOAD_BUDGET_COMPLETE:
					//onLoadBudget(note.getBody() as BizTripBudgetProxy);
					break;
/////////////////////
				case RequestApprovalMediator.APPROVAL_COMPLETE:					// 결재 요청  성공
					changeListView();
					break;
				case RequestApprovalMediator.APPROVAL_CANCEL:					// 결재 요청 취소
					//cancelApproval(_currentKey);
					break;
				
				//0609 일비계산
				case DailyCostProxy.LOAD_DAILY_COST_MULTI_COMPLETE:
					setDailyCost(note.getBody() as DailyCostProxy);
					break;
				case DailyCostProxy.LOAD_DAILY_COST_MULTI_FAILED:
					CommonAlert.showMessage(commonFacade.bundle, "(" + note.getBody().errCode + ")" + note.getBody().errText);
					break;					
				default:
					//trace(this.instanceID+"에서 처리 안된 Noti가 검출됨 : " + note.getBody());
					break;
			}
		}


		public function onYes(e:Event):void {
			PopUpManager.removePopUp(alertView);
			execApproval();
		}

		public function onNo(e:Event):void {
			PopUpManager.removePopUp(alertView);
		}

//shgoo : 2009.06.01
  		private function onLoadBudget(proxy:BizTripBudgetProxy):void
 		{
 			view.budget = proxy.budget;
/*
 			if(adjustBase == null) {
 				adjustBase = new AdjustBaseVO();
 			}
 			adjustBase.KOSTL = proxy.KOSTL;
 			adjustBase.WERT1 = proxy.budget;
 			adjustBase.WAERS = proxy.wares;
 			adjustBase.KDATE = new Date();
 			adjustBase.KURSF01 = 0;
 			adjustBase.KURSF02 = 0;
*/
 		}
//////////////////////

 		private function setDataToView(proxy:DailyBizTripProxy):void
 		{
 			//trace("setDatatoView: " + proxy.places.length);
 			
 			//0609
 			//view.dailyDP = proxy.places;
 			view.placeList 			= proxy.places; 
 			view.txtTitle.text		= AdjustmentVO(proxy.adjusts[0]).TRTITLE;
 			view.txtPurpose.text	= AdjustmentVO(proxy.adjusts[0]).PURPOSE;
 			
 			
 			view.summary.BEGDA		= AdjustmentVO(proxy.adjusts[0]).BEGDA;
 			view.summary.ENDDA		= AdjustmentVO(proxy.adjusts[0]).ENDDA;
 			
/*  			if(!bModify) {
 				if(String("11,21").indexOf(proxy.adjusts.getItemAt(0).TRSTATUS)>-1) {
 					view.btnModify.visible = true;
 				}
 				else {
 					view.btnModify.visible = false;
 				}
 			} */
 			view.strStatus = proxy.adjusts.getItemAt(0).TRSTATX;
			//출장비
 			view.dailyCost = proxy.adjusts.getItemAt(0).DAYPY;
 			
 			var sEduChk:String = proxy.adjusts.getItemAt(0).EDUCHK;
 			if(sEduChk == 'X'){
 				view.ckb.selected = true;
 				view.cbStartHour.enabled = true;
 				view.cbEndHour.enabled = true;
 				
 				view.cbStartHour.visible = true;
 				view.cbStartHour.includeInLayout = true;
 				view.cbEndHour.visible = true;
 				view.cbEndHour.includeInLayout = true;
 				view.hbHour.visible = true;
 				view.hbHour.includeInLayout = true;
 				view.lbHour.visible = true;
 				view.lbHour.includeInLayout = true;
 				
 			}else {
 				view.ckb.selected = false;
 				view.cbStartHour.enabled = false;
 				view.cbEndHour.enabled= false;
 				
 				view.cbStartHour.visible = false;
 				view.cbStartHour.includeInLayout = false;
 				view.cbEndHour.visible = false;
 				view.cbEndHour.includeInLayout = false;
 				view.hbHour.visible = false;
 				view.hbHour.includeInLayout = false;
 				view.lbHour.visible = false;
 				view.lbHour.includeInLayout = false;
 			}
 			
 			//view.txt.text  = proxy.adjusts.getItemAt(0).EDUTIME;
 			
 			view.cbStartHour.text	= proxy.adjusts.getItemAt(0).EBEGUZ;
 			view.cbEndHour.text		= proxy.adjusts.getItemAt(0).EENDUZ;
 		}

		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Event handler (from View, Internal or....)
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
		private function onAddRecord(event:Event):void
		{
			view.dailyDP.addItem(blankRecord());
			loadDailyCost(view.dailyDP.length);
		}

		private function onDelRecord(event:Event):void
		{
			for (var i:int=0; i<view.dailyDP.length; i++)
			{
				if(view.dailyDP.getItemAt(i).del) {
					view.dailyDP.removeItemAt(i--);
				}
			}
			if(view.dailyDP.length==0) {
				view.dailyDP.addItem(blankRecord());
			}
			loadDailyCost(view.dailyDP.length);
		}

		// 각 출장지별  End Date 계산
		private function alignPlaceDate():void
		{			
			for(var i:int=0; i<5; i++) {
				if((i+1)>=view.placeList.length) {
					view.placeList.getItemAt(i).ENDDA = view.summary.ENDDA;
					break;
				}
				var endda:Date = new Date(view.placeList.getItemAt(i+1).BEGDA);
				endda.date -= 1;
				if(Number(endda)<Number(view.placeList.getItemAt(i).BEGDA)) {
					endda = new Date(view.placeList.getItemAt(i).BEGDA);
				}
				view.placeList.getItemAt(i).ENDDA = endda;
			}
		}
		private function validData():Boolean
		{
			if(view.txtTitle.text==null || view.txtTitle.length<=0) {
				CommonAlert.showMessage(commonFacade.bundle, "ALERT_INVALID_TITLE", null, "ALERT_TITLE_INVALID_DATA", view);
				return false;
			}
			if( !checkPlaceDate() ) {
				CommonAlert.showMessage(commonFacade.bundle, "ALERT_INVALID_PLACE_DATE01", null, "ALERT_TITLE_INVALID_DATA", view);
				return false;
			}

			if( !checkPlaces() ) {
				CommonAlert.showMessage(commonFacade.bundle, "ALERT_INVALID_PLACE", null, "ALERT_TITLE_INVALID_DATA", view);
				return false;
			}
			
//			if(view.cbStartHour.selectedIndex >= view.cbEndHour.selectedIndex){
//				Alert.show('시작시간이 종료시간보다 큽니다.');				
//			}

			return true;
		}
		
		private function onSave(event:Event):void
		{
			alignPlaceDate();	
			if(!validData()) {
				return;
			}		
			//if(checkTables()) {
				var proxy:DailyBizTripProxy = facade.retrieveProxy(DailyBizTripProxy.NAME) as DailyBizTripProxy
				proxy.save(Variables.myPernr, false/*임시저장*/, TRSTATUS, key1, key2, bizTripPlaces(), adjustmentTable());
			//}
		}

		private function onApproval(event:Event):void
		{
			alignPlaceDate();	
			if(!validData()) {
				return;
			}					
			if(checkTables()) {
				/* 
				if(Number(view.txtDailyCost.dataValue)!=0) {
					bWaitingApproval = true;
					var proxy:DailyBizTripProxy = facade.retrieveProxy(DailyBizTripProxy.NAME) as DailyBizTripProxy
					proxy.save(Variables.myPernr, true, TRSTATUS, key1, key2, bizTripPlaces(), adjustmentTable());
				}
				else {
					view.txtDailyCost.setFocus();
					CommonAlert.showMessage(commonFacade.bundle, "출장비를 입력하셔야 승인요청을 할 수 있습니다.", null, "TITLE_DEFAULT", view);
				}
				 */
					bWaitingApproval = true;
					var proxy:DailyBizTripProxy = facade.retrieveProxy(DailyBizTripProxy.NAME) as DailyBizTripProxy
					proxy.save(Variables.myPernr, true, TRSTATUS, key1, key2, bizTripPlaces(), adjustmentTable());				 
			}
		}
		
		private function execApproval():void
		{
			if(checkTables()) {
	 			var approval:RequestApprovalMediator = facade.retrieveMediator(RequestApprovalMediator.NAME) as RequestApprovalMediator;
	 			if(approval==null) {
	 				approval = new RequestApprovalMediator(view, "04");
	 				facade.registerMediator(approval);
	 			}

	 			var appProxy:DailyApprovalProxy = facade.retrieveProxy(DailyApprovalProxy.NAME) as DailyApprovalProxy;
	 			appProxy.key =_currentKey;
	 			appProxy.amount = view.txtDailyCost.text;
	 			appProxy.dataProvider = view.placeList;
	 			appProxy.placeList 	 = view.placeList;
	 			appProxy.adjustmentTable = adjustmentTable_includ_date();
				appProxy.appType = (view.ckb.selected == true) ? true : false;
					 			
	 			approval.execRequest(view, appProxy);
			}

		}


		private function onCancelApproval():void
		{
			//Hourglass.remove();
		}


		private function checkPlaceDate():Boolean
		{

			for(var i:int=0; i<view.placeList.length; i++)
			{
				trace(
				"BEGDA"+i+" : " + DateUtil.toBasicString(view.placeList.getItemAt(i).BEGDA) + ", " + 
				"ENDDA"+i+" : " +DateUtil.toBasicString(view.placeList.getItemAt(i).ENDDA)+ ", -->" +
				"summaryBEGDA : " + DateUtil.toBasicString(view.summary.BEGDA) + ", " + 
				"summaryENDDA : " +DateUtil.toBasicString(view.summary.ENDDA)						
					  );				
				if(Number(view.placeList.getItemAt(i).BEGDA) < Number(view.summary.BEGDA) ||
					Number(view.placeList.getItemAt(i).ENDDA) < Number(view.summary.BEGDA) ||
					Number(view.placeList.getItemAt(i).BEGDA) > Number(view.summary.ENDDA) ||
					Number(view.placeList.getItemAt(i).ENDDA) > Number(view.summary.ENDDA))
					{

						return false;
					}
			}
			return true;
		}

		private function checkPlaces():Boolean
		{

			for(var i:int=0; i<view.placeList.length; i++)
			{
				if(StringUtil.NVL(view.placeList.getItemAt(i).BREN)=="")
				{
					return false;
				}
			}
			return true;
		}
		
		private function checkTables():Boolean
		{
			/* 
			var dateList:Array = new Array();
			for each(var vo:BizTripPlaceVO in view.dailyDP) {
				if(vo.BREN==null || vo.BREN == "") {
					CommonAlert.showMessage(commonFacade.bundle, "ALERT_INVALID_PLACE", null, "TITLE_DEFAULT", view);
					return false;
				}
				dateList.push(vo.BEGDA);
			}
			
			
			if(dateList.length>=2) {
				dateList.sort(Array.NUMERIC);
				var tmpDate:Date = new Date(dateList[0]);
				for(var i:int=1; i<dateList.length; i++) {
					tmpDate.date++;
					if(dateList[i].fullYear != tmpDate.fullYear ||
							dateList[i].month != tmpDate.month ||
							dateList[i].date != tmpDate.date)
					{
						CommonAlert.showMessage(commonFacade.bundle, "시내출장은 연속된 일자로만 동시 신청이 가능합니다.", null, "TITLE_DEFAULT", view);
						return false;
					}
				}
			}
			 */
			/*
//shgoo : 2009.06.25
//			if(Number(view.txtDailyCost.text)>view.dailyDP.length*5000) {
			var dataValue:String = view._budget.replace( new RegExp(",", "g"), "");
			if(Number(view.txtDailyCost.dataValue) > Number(dataValue) ) {
//////////////////////
				CommonAlert.showMessage(commonFacade.bundle, "ALERT_OVER_COST", null, "TITLE_DEFAULT", view);
				return false;
			}
			*/
			return true;
		}
		private function bizTripPlaces():Array
		{
			var table:Array = new Array;
			for each(var vo:BizTripPlaceVO in view.placeList) {
				var tmp:Object = new Object;
				tmp.SEQNO = vo.SEQNO;
				tmp.BEGDA = DateUtil.toBasicString(vo.BEGDA);
				tmp.ENDDA = DateUtil.toBasicString(vo.ENDDA);
				tmp.LAND1 = vo.LAND1;
				tmp.LANDTX = vo.LANDTX;
				tmp.LAGBN = vo.SEQNO;
				tmp.BREN = vo.BREN;

				//0511
				tmp.BREN1	 = vo.BREN1;	// 출장지 To
				tmp.TGBN	 = vo.TGBN;	// 구분
				tmp.CNUM	 = vo.CNUM;	// 차량번호
				tmp.DRIKM	 = vo.DRIKM;	// 거리(Km)
				
				table.push(tmp);
			}
			return table;
		}

		private function adjustmentTable():Array
		{
			var table:Array = new Array();
			var rec:Object = new Object;
			
			//0511
			rec["TRTITLE"] = view.txtTitle.text;
			rec["PURPOSE"] = view.txtPurpose.text;
			
			rec["WERT1"] = 0;
			if(Number(view.txtDailyCost.dataValue)!=0) {
				rec["DAYPY"] = Number(view.txtDailyCost.dataValue)/100; //view.dailyCost/100;
			}
			else {
				rec["DAYPY"] = 0;
			}
			
			if(view.ckb.selected == true){
				rec["EDUCHK"] = 'X';
			}else{
				rec["EDUCHK"] = '';
			}
			
			var strTime:String = view.cbStartHour.text;
			var endTime:String = view.cbEndHour.text;
			var arr:Array = strTime.split(":");
			var arr2:Array = endTime.split(":");
			
			
			var sStart:String;
			sStart = arr[0]+arr[1]+'00';
			rec["EBEGUZ"] = sStart;
			
			
			var sEnd:String;		
			sEnd = arr2[0]+arr2[1]+'00';
			rec["EENDUZ"] = sEnd;		
			
			//trace(rec["DAYPY"]);
			table.push(rec);
			return table;
		}

		private function adjustmentTable_includ_date():Array
		{
			var table:Array = new Array();
			var rec:Object = new Object;
			
			//0511
			rec["TRTITLE"] = view.txtTitle.text;
			rec["PURPOSE"] = view.txtPurpose.text;
			
			rec["BEGDA"] = view.begda.selectedDate;
			rec["ENDDA"] = view.enda.selectedDate;
			
			rec["WERT1"] = 0;
			if(Number(view.txtDailyCost.dataValue)!=0) {
				rec["DAYPY"] = Number(view.txtDailyCost.dataValue)/100; //view.dailyCost/100;
			}
			else {
				rec["DAYPY"] = 0;
			}
			//trace(rec["DAYPY"]);
			table.push(rec);
			return table;
		}

		private function onInputCancel(event:Event):void
		{
			changeListView();
		}

		private function changeListView():void
		{
			clearView();
			bActivated = false;
			view.initRenderer();
 			view.ckb.selected = false;
			facade.sendNotification(BizTripFacade.CHANGE_VIEW_BIZTRIP_LIST, this);
		}

		private function blankRecord():BizTripPlaceVO
		{
			var rec:BizTripPlaceVO = new BizTripPlaceVO();
			rec.BEGDA = new Date(currentDate);
			rec.ENDDA = new Date(currentDate);
			currentDate.date += 1;
			return rec;
		}

		private function setDailyCost(vo:DailyCostProxy):void
		{
			//view.dailyCost = vo.AMT;
			//view.maxDailyCost = vo.AMT;
			var d:DailyCostVO = vo.costList[0];
			view.txtDailyCost.text = d.AMT_F;
			trace(1); 
		}






		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Utility Functions
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
        private function get view():DailyBizTrip
        {
            return viewComponent as DailyBizTrip;
        }


	}
}